package com.supor.aiot.food.adapter;

import android.content.Context;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.supor.aiot.food.R;
import com.supor.aiot.food.bean.ChildList;
import com.supor.aiot.food.bean.ChildListBean;
import com.supor.aiot.food.bean.ClassifyBean;

import java.util.List;


public class ClassifyAdapter extends RecyclerView.Adapter<ClassifyAdapter.ClassifyHolder>{
    private List<ChildListBean> mList;
    private Context mContext;
    private OnClassifyClickListener recipeDeviceClick;
    public ClassifyAdapter(List<ChildListBean> mList, Context mContext , OnClassifyClickListener listener) {
        this.mList = mList;
        this.mContext = mContext;
        this.recipeDeviceClick = listener;
    }

    @NonNull
    @Override
    public ClassifyAdapter.ClassifyHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(mContext).inflate(R.layout.item_classfy_left,parent, false);
        return new ClassifyAdapter.ClassifyHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ClassifyHolder holder, int position) {
        ChildListBean childListBean = mList.get(position);

        holder.rlClassifyOuter.setOnClickListener(view -> {
            recipeDeviceClick.OnClassifyClick(position);
        });

        if (childListBean.isClicked()){
            holder.rlClassifyOuter.setBackgroundColor(mContext.getResources().getColor(R.color.white));
            holder.tvClassifyName.setTextColor(mContext.getResources().getColor(R.color.content_default));
            holder.tvClassifyName.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
        }else {
            holder.rlClassifyOuter.setBackgroundColor(mContext.getResources().getColor(R.color.white_fafafa));
            holder.tvClassifyName.setTextColor(mContext.getResources().getColor(R.color.content_assist));
            holder.tvClassifyName.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
        }
        holder.tvClassifyName.setText(childListBean.getClassificationName());
    }


    @Override
    public int getItemCount() {
        return mList.size();
    }

    public class ClassifyHolder extends RecyclerView.ViewHolder{
        private TextView tvClassifyName;
        private RelativeLayout rlClassifyOuter;
        public ClassifyHolder(@NonNull View itemView) {
            super(itemView);
            tvClassifyName=itemView.findViewById(R.id.tv_classify_name);
            rlClassifyOuter=itemView.findViewById(R.id.rl_classify_outer);
        }
    }

    public interface OnClassifyClickListener {
        void OnClassifyClick(int position);
    }

}
